package com.project.drugs;

import java.util.ArrayList;
import java.util.List;

import com.jdbc.util.BaseDAO;
import com.mysql.jdbc.Connection;

public class DrugsDAOImplements extends BaseDAO<Drugs> implements DrugsDAO {

	@Override
	public void insert(Connection conn, Drugs drugs) {
		String sql = "insert into Drugs(id,`name`,type,guige,money,number) values(?,?,?,?,?,?)";
		superUpdate(conn, sql, drugs.getId(),drugs.getName(),drugs.getType(),drugs.getGuige(),drugs.getMoney(),drugs.getNumber());
		
	}

	@Override
	public void deleteById(Connection conn, int id) {
		String sql = "delete from drugs where id = ?";
		superUpdate(conn, sql, id);
	}

	@Override
	public void update(Connection conn, Drugs drugs, int id) {
		String sql = "update drugs set id = ?,`name` = ?,type = ?,guige = ?,money = ?,number = ? where id = ?";
		superUpdate(conn, sql, drugs.getId(),drugs.getName(),drugs.getType(),drugs.getGuige(),drugs.getMoney(),drugs.getNumber(),id);
	}

	@Override
	public Drugs getDrugsById(Connection conn, int id) {
		String sql = "select id Id,`name` Name,type Type,guige Guige,money Money,number Number from drugs where id = ?";
		Drugs drugs = superSelect(conn, sql, id).get(0);
		return drugs;
	}

	@Override
	public List<Drugs> getAll(Connection conn) {
		String sql = "select id Id,`name` Name,type Type,guige Guige,money Money,number Number from drugs";
		ArrayList<Drugs> list = (ArrayList<Drugs>) superSelect(conn, sql, null);
		return list;
	}

	@Override
	public long getCount(Connection conn) {
		return 0;
	}

}
